<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        .layui-table-cell{
            height:50px;
            line-height: 50px;
        }
        .ui-input-class{
            width: 60%;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">承运商姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" id="tansportName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>

            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">审核</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">回退</a>
        </script>

    </div>
</div>


<div class="layui-form layuimini-form" id="CarTuAdd" style="display: none;">
    <div class="layui-form-item" style="margin-top: 20px;">
        <label class="layui-form-label required">承运商登录名</label>
        <div class="layui-input-block">
            <input type="text" name="loginName" id="loginName" lay-verify="required" lay-reqtext="承运商登录不能为空" placeholder="请输入承运商登录名" value=""
                   class="layui-input ui-input-class">
            <tip>填写好承运商登录的姓名</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">选择员工</label>
        <div class="layui-input-block" style="width: 20%;">
            <select class="ui-input-class" id="employeeId"  name="employeeId"  lay-verify="required">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">承运商姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="承运商姓名不能为空" placeholder="请输入承运商姓名" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">承运商密码</label>
        <div class="layui-input-block">
            <input type="text" name="password"  id="password" lay-verify="required" lay-reqtext="承运商密码不能为空" placeholder="请输入承运商密码" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机号</label>
        <div class="layui-input-block">
            <input type="number" name="tel"   id="tel"  lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">身份证号</label>
        <div class="layui-input-block">
            <input type="text" name="idCard"  id="idCard" lay-reqtext="运输人身份证号不可为空" placeholder="请输入身份证号" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">车牌号</label>
        <div class="layui-input-block">
            <input type="text" name="carNumber"   id="carNumber" lay-verify="required" lay-reqtext="车牌号不可为空" placeholder="请输入车牌号" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">选择车型</label>
        <div class="layui-input-block" style="width: 20%;">
            <select class="ui-input-class" id="carTypeId"  name="carTypeId"  lay-verify="required">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">马力</label>
        <div class="layui-input-block">
            <input type="text" name="carSoup"  id="carSoup" lay-verify="required" lay-reqtext="马力不可为空" placeholder="请输入马力" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">限载重量</label>
        <div class="layui-input-block">
            <input type="text" name="carLoad" id="carLoad" lay-verify="required" lay-reqtext="限载重量不可为空" placeholder="请输入限载重量" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">限载体积</label>
        <div class="layui-input-block">
            <input type="text" name="carVolume" id="carVolume" lay-verify="required" lay-reqtext="限载体积不可为空" placeholder="请输入限载体积" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">尺寸</label>
        <div class="layui-input-block">
            <input type="text" name="carSize"  id="carSize" lay-verify="required" lay-reqtext="尺寸不可为空" placeholder="请输入尺寸" value=""
                   class="layui-input ui-input-class">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">备注</label>
        <div class="layui-input-block">
            <textarea type="text" name="remake" id="remake" lay-verify="required" placeholder="请输入备注信息"  value=""
                   class="layui-textarea ui-input-class"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/carrier/queryAllCarAndCarTypeAndTansportUser',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                {type: "checkbox"},
                    {field:'tuid',hide:true},
                    {field: 'carNumber', title: '车牌号'},
                    {field: 'tansportName', title: '承运商姓名',width:100},
                    {field: 'carType', title: '车型'},
                    {field: 'carSoup', title: '马力'},
                    {field: 'carLoad', title: '限载重量'},
                    {field: 'carVolume', title: '限载体积'},
                    {field: 'carSize', title: '尺寸'},
                    {field: 'employeeId',width:100, title: '用户类别',templet:function(res){
                            if (res.employeeId > 0){
                                return "公司员工";
                            }else if(res.employeeId == 0){
                                return "承运人";
                            }
                        }},
                    {field: 'idCard', title: '身份证'},
                    {field: 'tegtime', title: '注册时间'},
                    {field: 'status', title: '状态',templet:function(res){
                            if (res.status == 0){
                                return "未审核";
                            }else{
                                return "正常";
                            }
                        }},
                    {field: 'untitled', title: '备注'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);


            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    tansportName: $("#tansportName").val()
                }
            }, 'data');

            return false;
        });
        //监听表单提交
        form.on('submit(saveBtn)', function(data){
            $.ajax({
                url:'/admin/carrier/addCarAndTransportUserAndCarRegister',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    layer.closeAll('page'); //关闭所有页面层
                    layer.msg(res.message)
                    //刷新表格
                    table.reload('currentTableId', {
                        url: '/admin/carrier/queryAllCarAndCarTypeAndTansportUser'

                    });


                }

            })

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加车辆和司机',
                    type: 1,
                    area: ['70%', '80%'],
                    content:$('#CarTuAdd'),
                    success:function (res) {
                        $("#loginName").val("");
                        $("#name").val("");
                        $("#password").val("");
                        $("#tel").val("");
                        $("#idCard").val("");
                        $("#carNumber").val("");
                        $("#carSoup").val("");
                        $("#carLoad").val("");
                        $("#carVolume").val("");
                        $("#carSize").val("");
                        $("#remake").val("");
                        $('#employeeId').html("");
                        $('#carTypeId').html("");
                        //新增页面车型下拉菜单
                        $.ajax({
                            url:'/admin/carrier/queryAllCarType',
                            type:'get',
                            dataType:'json',
                            success:function(data){
                                for(var i = 0; i < data.length; i++){
                                    $('#carTypeId').append(new Option(data[i].carType,data[i].carTypeId));
                                }
                                layui.form.render("select");
                            }
                        })
                        //新增页面员工下拉菜单
                        $.ajax({
                            url:'/admin/carrier/queryAllEmployee',
                            type:'get',
                            dataType:'json',
                            success:function(data){
                                for(var i = 0; i < data.length; i++){
                                    $('#employeeId').append(new Option(data[i].employeeName,data[i].employeeId));
                                }
                                layui.form.render("select");
                            }
                        })
                    }
                });

            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });


        //监听表格复选框选择
        table.on('checkbox(employeeTableFilter)', function (obj) {
            console.log(obj)
        });



        table.on('tool(employeeTableFilter)', function (obj) {

            var data = obj.data;

            //恢复运输人查看运输人的状态是否为正常
            var status = data.status;

            if (obj.event === 'edit') {


                layer.confirm('是否要更改运输人的状态？', function (index) {

                    if (status == 1){
                        layer.msg("此运输人正常无需恢复")
                    }else{
                        //修改运输人的状态
                        $.ajax({
                            url:'/admin/carrier/updateTransportUserStatus',
                            type:'post',
                            data:{
                                id:data.tuid,
                                status:1
                            },
                            dataType:'json',
                            success:function (res) {
                                layer.msg(res.message)
                                //刷新表格
                                table.reload('currentTableId', {
                                    url: '/admin/carrier/queryAllCarAndCarTypeAndTansportUser'

                                });
                            }
                        })
                    }

                });

            } else if (obj.event === 'delete') {

                layer.confirm('是否要更的状运输人的状态？', function (index) {

                    if (status == 0){
                        layer.msg("此运输人已是未审核状态")
                    }else{
                        //修改用户的状态
                        $.ajax({
                            url:'/admin/carrier/updateTransportUserStatus',
                            type:'post',
                            data:{
                                id:data.tuid,
                                status:0
                            },
                            dataType:'json',
                            success:function (res) {
                                layer.msg(res.message)

                                //刷新表格
                                table.reload('currentTableId', {
                                    url: '/admin/carrier/queryAllCarAndCarTypeAndTansportUser'

                                });

                            }
                        })
                    }

                });
            }
        });
    });
</script>

</body>
</html>
